/**
 * Project Name demo
 * File Name HbaseTest
 * Package Name com.huxiaosu.demo.hadoop.hbase
 * Create Time 2019/9/12
 * Create by name：liujie -- email: liujie@huxiaosu.com
 * Copyright © 2015, 2018, www.huxiaosu.com. All rights reserved.
 */
package com.huxiaosu.demo.hadoop.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

/**
 * Description
 *
 * @author liujie
 * @ClassName HbaseTest
 * @date 2019/9/12 14:43
 */
public class HbaseTest {

    public static void main(String[] args) throws IOException {
        
        Configuration configuration = HBaseConfiguration.create();
        configuration.set("hbase.zookeeper.quorum", "172.25.78.211");
        configuration.set("hbase.zookeeper.property.clientPort", "2181");
        Connection connection = ConnectionFactory.createConnection(configuration);
        Admin admin = connection.getAdmin();
        String tableName = "test-liujie";
        String columnFamily = "test-liujie";
        TableName name = TableName.valueOf(tableName);
        if (admin.tableExists(name)) {
            System.out.println("table:" + tableName + " exists, no creating");
        } else {
            HTableDescriptor td = new HTableDescriptor(name);
            HColumnDescriptor family = new HColumnDescriptor(columnFamily);
            td.addFamily(family);
            admin.createTable(td);
            System.out.println(tableName + " 表创建成功！");
        }

    }
}
